<extend name="Base/common"/>
<block name="body">
	<div class="mui-content mui-content-padded ">
	    <form action="__URL__/reg" class="mui-input-group login_form">
	    	<div class="mui-input-row">
	    	    <label><img src="__IMG__/icon_mobile.png"></label>
	    	    <input type="text" id="mobile" class="mui-input-clear" placeholder="手机号">
	    	</div>
	        <div class="mui-input-row">
	    	    <label><img src="__IMG__/icon_lock.png"></label>
	        	<input type="password" id="pwd" class="mui-input-password" placeholder="请输入密码">
	        </div>
	        <div class="mui-input-row">
	    	    <label><img src="__IMG__/icon_lock.png"></label>
	        	<input type="password" id="repwd" class="mui-input-password" placeholder="请再次输入密码">
	        </div>
	        <div class="getcode">
	        	<input type="text" id="code" style="width: 60%;" placeholder="输入验证码">
	        	<button type="button" id="btn_getcode" class="mui-btn">获取验证码</button>
	        </div>
	        <div class="btn_sure">
	        	<button type="button" id="btn_submit" class="mui-btn mui-btn-block btn_submit">提交</button>
	        </div>
	    </form>
	</div>
</div>
</block>
<block name="script">
	<script type="text/javascript">
		$("#btn_getcode").on('click',function(){
			if ($(this).hasClass('mui-disabled')) {
				return false;
			}
			var mobile = $("#mobile").val();
			if (mobile == '') {
				mui.alert("请输入手机号");
				return ;
			}
			$.post("{:U('/api/public/verify')}",{"user":mobile,"type":"forgotten"},function(result){
				if (result.code == 1) {
					mui.toast("发送成功");
					$("#btn_getcode").addClass('mui-disabled');
					sleep = 60;
					interval = setInterval(function(){
							if(sleep <= 0){
								clearInterval(interval);
								interval = null;
								$("#btn_getcode").removeClass('mui-disabled');
								$("#btn_getcode").text("重新发送");
							}else{
								$("#btn_getcode").text("重新发送("+ sleep-- +")");
							}
						},1000);
				}else{
					mui.alert(result.message);
				}
			},'json');
		});
		$("#btn_submit").on('click',function(){
			var mobile = $("#mobile").val();
			var pwd = $("#pwd").val();
			var repwd = $("#repwd").val();
			var verify = $("#code").val();
			if (mobile == '') {
				mui.alert("请输入手机号");
				return ;
			}
			if (pwd == '') {
				mui.alert("请输入密码");
				return ;
			}
			if (pwd !== repwd) {
				mui.alert("两次密码输入不一致");
				return ;
			}
			if (verify == '') {
				mui.alert("请输入验证码");
				return ;
			}
			$.post("{:U('/api/user/resetPassword')}",{"user":mobile,"pwd":pwd,"repwd":repwd,"verify":verify},function(result){
				if (result.code !== 1) {
					mui.alert(result.message);
				}else{
					mui.alert("操作成功");
					mui.later(function(){						  
						location.href = "{:U('index')}";
					},1000)
				}
			},'json');
		});
	</script>
</block>
